package server;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;

import common.Board;
import common.Company;
import common.Coordinate;
import common.History;
import common.IUI;
import common.Player;
import common.Profile;
import common.enumCompany;

public class CompPlayer implements IUI, Serializable
{	
    private static final long serialVersionUID = -4163118011207676185L;
    Board gameBoard;
	Player compPlayer;
	String compName = null;
	int num = 0;
	
	public void setTurnInfo(Board board,Player player)
	{
		gameBoard = board;
		compPlayer = player;		
		compPlayer.setNotHuman();
	}
    
	public void printBoard()
    {    	
    }
    

	public void printInfo()
    {    	
    }    
    
	public Coordinate printPickTileDialog()
    {
    	num %= compPlayer.getTiles().size();
    	
    	Coordinate chosenTile = compPlayer.getTiles().get(num).getLocation();
    	
    	num++;
    	return chosenTile;
    }
    
	public int[] printStocksToBuyDialog(Company[] companies)
    {    	
    	int[] StocksToBuy = new int[companies.length];
    	
    	if (num%2==0)
    	{    	
    		for (Company company : companies)
    		{
    			if (company.isOnBoard() && company.getStockValue() <= compPlayer.getCash())
    			{
    				StocksToBuy[company.getCompanyIndex()] = 1;
    				break;
    			}
    		}
    	}    	
    	
    	num++;
    	return StocksToBuy;
    }
    
	public void printError(int errorIndex)
    {    	
    }
    
	public void printMessage(int msg,int ...args)
    {    	
    }
    
	public void setPlayersName(String[] playerNames)
    {    	
    }
    
	public void printSellCompanyDialog(Company soldCompany, Company buyingCompany, List<Player> topShareHolders, 
            List<Player> secondShareHolders, int prizeMoney, int secondprizeMoney, Player[] players)
    {    	
    }
    
	public int printSellCompanySell(Company soldCompany)
    {
		enumCompany soldCompanyEnum = enumCompany.values()[soldCompany.getCompanyIndex()];
    	if (compPlayer.getCompanyStocks(soldCompanyEnum) > 0)
    	{
    		return 1;
    	}
    	return 0;
    }
    
	public int printSellCompanyChange(Company soldCompany, Company buyingCompany)
    {		
		if (num%2 == 0)
		{
			enumCompany soldCompanyEnum = enumCompany.values()[soldCompany.getCompanyIndex()];
	    	if (compPlayer.getCompanyStocks(soldCompanyEnum) > 1)
	    	{
	    		num++;
	    		return 2;
	    	}
		}
		num++;
    	return 0;
    }
    
	public void printEndGameResults(Map<Integer,List<Player>> finalStandings)
    {    	
    }
    
	public enumCompany printChooseCompanyDialog(Company[] companies)
    {    	
    	num %= companies.length;
    	
    	enumCompany chosenCompany = enumCompany.values()[num];
    	num++;
    	return chosenCompany;
    }
    
	public void printSortBetweenSameSizeCompanies(List<Company> sameSizedCompanies, int size)
    {    	
    }
    
	
	public void printHoF(Map<Integer,List<String>> hof)
    {    	
    }
    
	public void printMessage(String str) 
	{
	}
	
	public String getPlayerName()
    {
		if (compName == null)
		{
			compName = "Computer" + num;
			num++;
		}
				
		return compName;		
    }
	
	public int getNumberOfPlayers()
	{
		//This method will never be called..
		return -999;
	}
	
	public int getUserSetupDecision()
	{
		//this method will never be called..
		return -999;
	}

    public void clearScreen() {
        
    }

    public void setTurnInfo(Player player) {
        
    }

	public void setBeginningOfTurn(boolean beginningOfTurn)
			throws RemoteException {
		
	}

	public boolean getEndGame() throws RemoteException {
		return false;
	}


    public boolean closeExportedObject() throws RemoteException {
        return true;
    }

	public String getPlayerName(int i) {
		return null;
	}

	public int getUserGameTypeDecision() {
		return 0;
	}

	public void printTextFile(String FileName) throws RemoteException 
	{
	}

	public String getLoadFileName() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getSaveFileName() {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean getYesNoQuestionAnswer() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean getLoadGame() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean getRedoGame() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean getSaveGame() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean getUndoGame() {
		// TODO Auto-generated method stub
		return false;
	}

	public void pickTileDialogText(int tilesPerPlayer) {
		// TODO Auto-generated method stub
		
	}

	public void setUndone(boolean unDone) {
		// TODO Auto-generated method stub
		
	}

	public boolean getOptionMade() throws RemoteException {
		// TODO Auto-generated method stub
		return false;
	}

	public void resetOptions() throws RemoteException {
		// TODO Auto-generated method stub
		
	}

	public void setFirstTurn() throws RemoteException {
		// TODO Auto-generated method stub
		
	}

    public String[] getLoginDetails(int tryNum) {
        // TODO Auto-generated method stub
        return null;
    }

    public Profile getRegistrationDetails() throws RemoteException {
        // TODO Auto-generated method stub
        return null;
    }

    public int getUserLoginDecision() throws RemoteException {
        // TODO Auto-generated method stub
        return 0;
    }

	public void printHistory(History history) throws RemoteException {
		// TODO Auto-generated method stub
		
	}

	public int getUserRoomDecision(int N) throws RemoteException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getUserSetupDecision(boolean guest) throws RemoteException {
		// TODO Auto-generated method stub
		return 0;
	}

	public String changeEmailDialog() throws RemoteException {
		// TODO Auto-generated method stub
		return null;
	}

	public String changePasswordDialog(String oldPassword)
			throws RemoteException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getUserProfileDecision() throws RemoteException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getHostAddressDecision() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getPortDecision() {
		// TODO Auto-generated method stub
		return 0;
	}
}
